home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / opt.c < prev    next >
C/C++ Source or Header  |  1995-10-03  |  4KB  |  108 lines

  1. #include "vbc.h"
  2.  
  3. void simple_regs(void)
  4. /*  haelt Variablen in Registern, simple Version            */
  5. {
  6.     int i2,i,j;int pri;struct Var *v;
  7.     struct IC *icp,*start=first_ic;
  8.     if(!first_ic) return;
  9.     for(i2=0;i2<=MAXR*4;i2++){
  10.         int only_best,pointertype;
  11.         if(i2<=MAXR*2){i=i2;only_best=1;} else {i=i2/2;pointertype=only_best=0;}
  12.         if(i>MAXR){
  13.             i-=MAXR;
  14.             if(regsv[i]) continue;
  15.         }else{
  16.             regsv[i]=0;
  17.             /*  Ziehe Scratchregister vor, wenn kein Funktionsaufruf */
  18.             /*  erfolgt, sonst erst andere                           */
  19.             if(!function_calls&&!regscratch[i]) continue;
  20.             if(function_calls&®scratch[i]) continue;
  21.         }
  22.         if(regused[i]) continue;
  23.         /* Nicht-Scratchregister muessen einmal gesichert und wieder    */
  24.         /* hergestellt werden, Scratchregister bei jedem Call           */
  25.         if(regscratch[i]) pri=function_calls*2; else /*pri=2;*/ pri=0;
  26.         for(j=0;j<=1;j++){
  27.             if(j==0) v=merk_varf; else v=first_var[1];
  28.             while(v){
  29.                 if(v->storage_class==AUTO||v->storage_class==REGISTER){
  30.                     if(!(v->flags&USEDASADR)&&!(v->vtyp->flags&VOLATILE)){
  31.                         if(only_best&&v->vtyp->next) pointertype=v->vtyp->next->flags;
  32.                         if(v->priority>pri&®ok(i,v->vtyp->flags&31,pointertype)){
  33.                             regsv[i]=v;pri=v->priority;
  34.                         }
  35.                     }
  36.                 }
  37.                 v=v->next;
  38.             }
  39.         }
  40.         if(regsv[i]){
  41.             if(DEBUG&1) printf("Assigned <%s> to %s\n",regsv[i]->identifier,regnames[i]);
  42.             regsv[i]->priority=0;regused[i]=1;
  43.             if(regsv[i]->offset<0&&!(regsv[i]->flags&CONVPARAMETER)){
  44.                 icp=(struct IC *)mymalloc(ICS);
  45.                 icp->q1.am=icp->q2.am=icp->z.am=0;
  46.                 icp->code=ASSIGN;
  47.                 icp->typf=regsv[i]->vtyp->flags&31;
  48.                 icp->q1.flags=VAR;
  49.                 icp->q1.v=regsv[i];
  50.                 icp->q1.val.vlong=l2zl(0L);
  51.                 icp->q2.flags=0;
  52.                 icp->q2.reg=szof(regsv[i]->vtyp);
  53.                 icp->z.flags=REG;
  54.                 icp->z.reg=i;
  55.                 icp->next=first_ic;
  56.                 icp->prev=0;
  57.                 first_ic->prev=icp;
  58.                 first_ic=icp;
  59.             }
  60.             icp=(struct IC *)mymalloc(ICS);
  61.             icp->q1.am=icp->q2.am=icp->z.am=0;
  62.             icp->code=ALLOCREG;
  63.             icp->q1.flags=REG;
  64.             icp->q1.reg=i;
  65.             icp->q2.flags=icp->z.flags=icp->typf=0;
  66.             icp->next=first_ic;
  67.             icp->prev=0;
  68.             first_ic->prev=icp;
  69.             first_ic=icp;
  70.             icp=(struct IC *)mymalloc(ICS);
  71.             icp->q1.am=icp->q2.am=icp->z.am=0;
  72.             icp->code=FREEREG;
  73.             icp->q1.flags=REG;
  74.             icp->q1.reg=i;
  75.             icp->q2.flags=icp->z.flags=icp->typf=0;
  76.             icp->next=0;
  77.             add_IC(icp);
  78.         }
  79.     }
  80.     icp=start;
  81.     while(icp){
  82.         if((icp->code==ALLOCREG||icp->code==FREEREG)&®sv[icp->q1.reg]){
  83.         /*  irgendwelche allocreg/freereg im Code entfernen     */
  84.         /*  sollte nur beim Returnregister vorkommen            */
  85.             struct IC *m=icp->next;
  86.             remove_IC(icp);
  87.             icp=m;continue;
  88.         }
  89.         for(i=1;i<=MAXR;i++){
  90.             if(!regsv[i]) continue;
  91.             if((icp->q1.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->q1.v==regsv[i]){
  92.                 icp->q1.flags|=REG;
  93.                 icp->q1.reg=i;
  94.             }
  95.             if((icp->q2.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->q2.v==regsv[i]){
  96.                 icp->q2.flags|=REG;
  97.                 icp->q2.reg=i;
  98.             }
  99.             if((icp->z.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->z.v==regsv[i]){
  100.                 icp->z.flags|=REG;
  101.                 icp->z.reg=i;
  102.             }
  103.         }
  104.         icp=icp->next;
  105.     }
  106. }
  107.  
  108.